<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
Route::get('/', 'Api\HomeController@index');

Route::namespace('Api')->group(function () {
    // 登陆注册
    Route::post('login', 'LoginController@index'); # 登录
    Route::post('logout', 'LoginController@logout'); # 登出
    Route::post('code/{type}', 'VerifyCodeController@index')
        ->where('type', "register|login|pwd_reset|pwd_forget"); # 发送验证码
    Route::post('code/verify', 'VerifyCodeController@verify'); # 验证验证码

    // 商品模块
    Route::post('home', 'HomeController@index'); # 首页
    Route::post('category', 'CategoryController@index'); # 分类
    Route::post('products', 'ProductController@index')->name('api.product.index'); # 商品列表
    Route::post('product/show', 'ProductController@show')->name('api.product.show'); # 商品详情
    Route::post('products/coupon', 'CouponController@index'); # 优惠商品

    // 地址
    Route::post('address', 'AddressController@getAddress');// 获取地域信息
    Route::post('about', 'CommonController@about');
    Route::post('offline', 'CommonController@offline');
    Route::post('suggestion', 'CommonController@suggestion');

    // 评价
    Route::post('comments', 'CommentController@index'); #获取商品评价

    Route::middleware('auth:api')->group(function () {
        // 个人基本信息
        Route::post('password', 'UserController@password'); # 修改密码
        Route::post('me', 'UserController@index'); # 个人信息
        Route::post('me/permission', 'UserController@permission'); # 会员权限
        Route::post('me/address', 'UserController@address'); # 保存地址
        Route::post('me/address/default', 'UserController@defaultAddress'); # 设置默认地址
        Route::get('me/address', 'UserController@getAddress'); # 地址列表

        // 个人详细信息
        Route::post('/me/detail', 'UserController@detail'); # 详细信息
        Route::post('/me/update', 'UserController@update'); # 更新详细信息

        // 钱包
        Route::post('me/pocket', 'PocketController@index'); # 账户余额
        Route::post('me/pocket/password', 'PocketController@password'); # 设置支付密码
        Route::post('me/pocket/logs', 'PocketController@logs'); # 账单明细

        // 购物车
        Route::post('cart', 'CartController@index'); # 购物车列表
        Route::post('cart/store', 'CartController@store'); # 添加购物车
        Route::post('cart/delete', 'CartController@delete'); # 删除购物车
        Route::post('cart/update', 'CartController@update'); # 更新购物车

        // 订单
        Route::post('order', 'OrderController@index'); # 订单列表
        Route::post('order/show', 'OrderController@show'); # 订单详情
        Route::post('order/store', 'OrderController@store'); # 生成订单
        Route::post('order/prepare', 'OrderController@prepare'); # 商品结算
        Route::post('order/cancel', 'OrderController@cancel'); # 订单取消
        Route::post('order/delete', 'OrderController@delete'); # 删除订单
        Route::post('order/receive', 'OrderController@receive'); # 确认收货

        // 优惠券
        Route::post('coupon/receive', 'CouponController@receive'); # 领取优惠券

        // 评价
        Route::post('comments/store', 'CommentController@store'); # 评价商品
        Route::post('comments/delete', 'CommentController@delete'); # 删除评价

        // 上传
        Route::post('upload/config', 'UploadController@config');

        // 收藏
        Route::post('collections/attach', 'CollectionController@attach'); # 添加收藏
        Route::post('collections/detach', 'CollectionController@detach'); # 取消收藏
        Route::post('collections/products', 'CollectionController@product'); # 收藏列表

        // 支付相关
        Route::post('pay/order', 'PayController@index'); # 订单支付
    });

    // 支付结果通知
    Route::any('pay/notify/{payment}', 'PayController@notify')
        ->where('payment', 'wechat|alipay')
        ->name('api.pay.notify');

    // 临时测试地址
    Route::get('pay/order/web', 'PayController@web'); # 订单支付测试地址
});
